package com.mouse.hxsj.service;

import com.mouse.damo.micro.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

/**
 * 长流程
 */
@Slf4j
@Component
public class ActionService {
    public static void main(String[] args) {
        Com com1 = new Com();
        com1.bind(722974);
        double2(com1);
        Sleep.sleep(1000);
        shenMu(com1, new Date());
        //
        Calendar instance = Calendar.getInstance();
        instance.add(Calendar.HOUR_OF_DAY, 4);
        Com com2 = new Com();
        com2.setHwnd(4589312);
        double2(com2);
        Sleep.sleep(1000);
        shenMu(com2, instance.getTime());
        //
        Com com3 = new Com();
        com3.setHwnd(2623318);
        double2(com3);
    }

    public static Thread shenMu(Com com, Date date) {
        Press press = new Press(com);
        Thread thread = new Thread(() -> {
            while (true) {
                press.keyPress(Press.F4);
                Sleep.sleep((2 * 60 * 60 + 5) * 1000);
            }
        });
        return thread;
    }

    public static Thread most(Com com) {
        Press press = new Press(com);
        Thread thread = new Thread(() -> {
            while (true) {
                press.keyPress(Press.F5);
                Sleep.sleep((15 * 60 + 30) * 1000);
            }
        });
        thread.start();
        return thread;
    }

    public static Thread double2(Com com) {
        Thread thread = new Thread(() -> {
            while (true) {
                new ActionService().expTwo2hour(com);
                Sleep.sleep((2 * 60 * 60 + 10) * 1000);
            }
        });
        thread.start();
        return thread;
    }

    public static Thread shengJiJob(Com com, boolean tuDiFlag) {
        Thread thread = new Thread(() -> {
            while (true) {
                ActionService.shengJi(com);
                Sleep.sleep(1000);
                if (tuDiFlag) {
                    tuDi(com);
                    Sleep.sleep(200);
                }
                Sleep.sleep(10 * 1000);
            }
        });
        thread.start();
        return thread;
    }

    /**
     * 双倍经验2小时
     *
     * @param com
     * @return
     */
    public boolean expTwo2hour(Com com) {
        try {
            Press press = new Press(com);
            Mouse mouse = new Mouse(com);
            FindPic findPic = new FindPic(com);
            int[] pic = findPic.findPic(400, 4, 1343, 568
                    , "action/双.bmp", "203040", 0.8, 0);
            mouse.mouseClick(pic[1], pic[2], true);//TODO
            Sleep.sleep(500);
            int[] pic1 = findPic.findPic(237, 48, 1079, 614,
                    "action/经.bmp", "203040", 0.8, 0);
            if (pic1[0] == -1) return false;
            mouse.mouseClick(pic1[1], pic1[2] + 250, true);//TODO
            Sleep.sleep(500);
            mouse.mouseClick(pic1[1], pic1[2] + 360, true);//TODO
            Sleep.sleep(500);
            mouse.mouseClick(pic1[1], pic1[2] + 303, true);//TODO
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return false;
        }
        return true;
    }

    public static void shengJi(Com com) {
        FindPic findPic = new FindPic(com);
        int[] pic1 = findPic.findPic(0, 0, 1079, 614,
                "action/升级.bmp", "203040", 0.8, 0);
        if (pic1[0] != -1) new Mouse(com).mouseClick(pic1[1] + 5, pic1[2] + 5, true);
    }

    public static void tuDi(Com com) {
        FindPic findPic = new FindPic(com);
        int[] pic1 = findPic.findPic(0, 0, 1079, 614,
                "action/很好.bmp", "203040", 0.8, 0);
        if (pic1[0] != -1) {
            Mouse mouse = new Mouse(com);
            mouse.mouseClick(pic1[1] - 66, pic1[2] + 5, true);
            Sleep.sleep(300);
            mouse.mouseClick(pic1[1], pic1[2] + 90, true);
            Sleep.sleep(1000);
        }
    }
}
